package com.algorithm.ch1.cjm.array;

/**
 * @Author: Jie Ming Chen
 * @Date: 2019-02-19
 * @Version 1.0
 */
public class HashCodeTest {

    public static int count(int[] nums) {
        int sum = 0;
        int n = nums.length - 1;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i] * 31^(n- i);
        }
        return sum;
    }

    public static int hashCode(int[] nums) {
        int h = 0;
        for (int i = 0; i < nums.length; i++) {
            h = 31 * h + nums[i];
        }
        return h;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3};
        int count = count(nums);
        System.out.println(count);

        int hashCode = hashCode(nums);
        System.out.println(hashCode);

        System.out.println(2^2);
    }
}
